<template>
  <!-- 头部 -->
  <LoginHeader>欢迎登录</LoginHeader>
  <!-- 主体登录区域 -->
  <section class="login-section">
    <div class="wrapper">
      <nav>
        <a href="javascript:;" @click="clickTab('account')">账户登录</a>
        <a href="javascript:;" @click="clickTab('ewm')">扫码登录</a>
      </nav>
         <!-- 表单 -->
      <keep-alive>
        <component :is="componentName[curName]" />
      </keep-alive>
    </div>
  </section>
  <!-- 顶部 -->
  <LoginFooter />
</template>

<script>
import LoginHeader from './components/login-header'
import LoginFooter from './components/login-footer'
import LoginEwm from './components/login-ewm'
import LoginAccount from './components/login-account'
import { ref, shallowRef } from 'vue'
// 创建枚举
const component = {
  ewm: LoginEwm,
  account: LoginAccount
}
export default {
  name: 'Login',
  components: {
    LoginHeader,
    LoginFooter
  },
  setup () {
    const curName = ref('account')
    function clickTab (name) {
      curName.value = name
    }
    // 浅代理 .value属性是一个普通的对象 不再是一个Proxy对象
    const componentName = shallowRef(component)
    return {
      curName,
      clickTab,
      componentName
    }
  }
}
</script>

<style scoped lang="less">
.login-section {
  background: url(../../assets/images/login-bg.png) no-repeat center / cover;
  height: 488px;
  position: relative;
  .wrapper {
    width: 380px;
    background: #fff;
    min-height: 400px;
    position: absolute;
    left: 50%;
    top: 54px;
    transform: translate3d(100px,0,0);
    box-shadow: 0 0 10px rgba(0,0,0,.15);
    nav {
      height: 55px;
      border-bottom: 1px solid #f5f5f5;
      display: flex;
      padding: 0 40px;
      text-align: right;
      align-items: center;
      a {
        flex: 1;
        line-height: 1;
        display: inline-block;
        font-size: 18px;
        position: relative;
        &:first-child {
          border-right: 1px solid #f5f5f5;
          text-align: left;
        }
        &.active{
          color: @xtxColor;
          font-weight: bold;
        }
      }
    }
  }
}
</style>
